import axios from "axios";
import { initList } from '../services/home'

export default {
    // 命名空间
    namespace: 'home',
    state: {
        count: 200,
        list: []
    },
    // 同步修改数据
    reducers: {
        ADD_COUNT(state, action) {
            state.count += 1
            return { ...state }
        },
        SET_LIST(state, action) {
            const NewState = JSON.parse(JSON.stringify(state))
            NewState.list = action.data
            return NewState
        }
    },
    // 异步修改数据 (集成saga)
    effects: {
       *INIT(payload, { put }) {
            const data = yield initList()
            yield put({ type: "SET_LIST", data: data.data.message })
       } 
    },
    subscriptions: {
        init({ dispatch }) {
            dispatch({ type: "INIT" })
        },
        // auth({ history }) {
        //     if (history.location.pathname === "/home") {
        //         history.push("/my")
        //     }
        // }
    }

    // subscriptions: {
    //     setup({ dispatch, history }) {  // eslint-disable-line
    //     },
    // },

    // effects: {
    //     *fetch({ payload }, { call, put }) {  // eslint-disable-line
    //         yield put({ type: 'save' });
    //     },
    // },

    // reducers: {
    //     save(state, action) {
    //         return { ...state, ...action.payload };
    //     },
    // },
};
